Skip to content

feat(vault-jwt): allow specifying the vault jwt token directly #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

moo-im-a-cow
Copy link
Contributor

this PR allows you to pass the desired jwt token to the vault-jwt module as a variable, for cases when you want to use a different jwt token to the one used to authenticate to vault

if not specified, it defaults to data.coder_workspace_owner.me.oidc_access_token.

@cdr-bot cdr-bot bot added the community Pull Requests and issues created by the community. label Apr 22, 2025
Comment on lines +23 to +29
variable "vault_jwt_token" {
type = string
description = "The JWT token used for authentication with Vault."
default = null
sensitive = true
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example use case on how you would provide that token to the module? Are you fetching it externally through some API or another provider?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://gist.github.com/moo-im-a-cow/002e18137f5956893e610f85096e04e9#file-main-tf-L394-L422
this is how i'm currently generating the token, using another provider in the template

i'm doing this because i'd like to use a dedicated jwt token issued by coder for the workspace instead of passing through the token used to authenticate to coder

more info here: coder/coder#13127 (comment)

do you want the examples added to the commit in some way?
i'm unsure how documentation works here, but i'll do whatever is needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want the examples added to the commit in some way?
i'm unsure how documentation works here, but i'll do whatever is needed

We usually add example Terraform snippets in the README.md to guide users on possible ways the module can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've now added an example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I would appreciate it if we could also add a vault policy that can use this new jwt token, scoped to workspace metadata.

Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a vault expert at all. But as far as I understand the the workspace scoped secrets need to be pre created in vault. How would one do that.
In other words, I agree with use case to provide workspace only secrets access but is concerned if it makes the config difficult on the vault side. How would one provision these secrets? For what type of secrets this is most useful for.

Thanks.

Comment on lines +23 to +29
variable "vault_jwt_token" {
type = string
description = "The JWT token used for authentication with Vault."
default = null
sensitive = true
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I would appreciate it if we could also add a vault policy that can use this new jwt token, scoped to workspace metadata.

@moo-im-a-cow
Copy link
Contributor Author

moo-im-a-cow commented Apr 22, 2025

Not a vault expert at all. But as far as I understand the the workspace scoped secrets need to be pre created in vault. How would one do that.

one option is for someone with permission to create at the correct path would have to create them with the relevant command, an admin user with their "access everything" policy

e.g. for kv, it would be something like vault kv put -mount=kv apps/coder/username/workspace/supersecret password=password
image

but more likely, the workspace user would generate a secret inside the workspace, and save it to vault (by running the above command in the workspace), and then it can never be retrieved from outside

policy could be created for allowing anyone access as long as they are accessing using a specific coder template

additionally, one of the scenarios im considering is an admin user who only has admin access from inside coder. policies granting full access to whatever, but only when authenticated with a specific mount/role, theres no specific secret, more just any and all secrets
(similar to how the only user with permission to create and manage auth methods and engines in my vault instance is a token generated by gitlab for a CI job in a specific repository, using exactly the same sort of configuration here)

something similar i already have set up, is that a specific k8s service account in the coder namespace is the only user capable of accessing the oidc client secret for coder, which is stored in vault
the disk pvc service account in k8s is the only user that can create or view disk encryption keys for the cluster, also in vault

another example of how this could be useful is allow you to use vault to generate k8s keys or aws access keys, but you can only do it from a trustworthy environment, you must be using template X

config difficult on the vault side
it can be as easy or difficult as the person managing it is willing to make it, assign an existing policy to the role, doesnt even need any configuration other than what they already have, or they can use every variable available
just because the variables are included in the token doesnt mean you have to use them in vault,
but if they're there, you have the option to use them if you want

additionally, this is just one of many many ways to set it up, you could have it generate with none of the fields and just authenticate the user, link the token to the user's entity in vault, 1:1 same permissions the user has outside, same secrets
or you can do more complex like what i'm using it for

but the ability to make complex policies based on data from the authentication source is exactly what you want with vault.

the difficulty is sorta similar to coder templates, if you wanted to you could make it so complicated and difficult to use, or you could make it easy, that's entirely up to the person who generates the token to pass to the module, and the person who writes the policies to decide what to do

I would appreciate it if we could also add a vault policy that can use this new jwt token

done, I added an example vault policy, as well as an example command for configuring the mount role

@matifali
Copy link
Member

Hi @moo-im-a-cow can you run bun fmt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Pull Requests and issues created by the community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants